using UnityEngine;

namespace HybridCLR.Extension
{
    public class ResourcesAddressable : IResources
    {
        public System.Threading.Tasks.Task<T> LoadAssetAsync<T>(string path) where T : Object
        {
            System.Threading.Tasks.TaskCompletionSource<T> tcs = new System.Threading.Tasks.TaskCompletionSource<T>();
            var handle = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<T>(path);
            handle.Completed += result =>
            {
                tcs.SetResult(result.Result);
            };
            return tcs.Task;
        }

        public void Release<T>(T obj) where T : Object
        {
            UnityEngine.AddressableAssets.Addressables.Release(obj);
        }
    }
}